package com.hollysys.hollimsa.biz.istio.destinationrule.dao;


import me.snowdrop.istio.api.networking.v1beta1.DestinationRule;
import me.snowdrop.istio.client.IstioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class DestinationRuleDao {
    @Autowired
    private IstioClient istioClient;

    public List<DestinationRule> listDestinationRule(String namespace) {
        return istioClient.v1beta1DestinationRule().inNamespace(namespace).list().getItems();
    }

    /**
     * 编辑组件
     *
     * @param destinationRule 规则
     * @return 修改状态
     */
    public DestinationRule createOrReplaceDestinationRule(DestinationRule destinationRule,String namespace) {
        return istioClient.v1beta1DestinationRule().inNamespace(namespace).createOrReplace(destinationRule);

    }

    public boolean deleteDestinationRule(String name,String namespace) {
        return istioClient.v1beta1DestinationRule().inNamespace(namespace).withName(name).delete();
    }

    public DestinationRule getDestinationRuleDetail(String name,String namespace) {
        return istioClient.v1beta1DestinationRule().inNamespace(namespace).withName(name).get();
    }

    public List<DestinationRule> drData4DropDown(String namespace) {
        return istioClient.v1beta1DestinationRule().inNamespace(namespace).list().getItems();
    }
}
